﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace msdcp
{
    internal class MsdVersion
    {
        private int doors;
        private int edition;
        private int build;
        private ushort verValue;

        public int Doors
        {
            get { return doors; }
            set 
            {
                doors = value;
                UpdateVersionValue();
            }
        }

        public int Edition
        {
            get { return edition; }
            set 
            {
                edition = value;
                UpdateVersionValue();
            }
        }

        public int Build
        {
            get { return build; }
            set 
            {
                build = value;
                UpdateVersionValue();
            }
        }

        public MsdVersion(int val)
        {
            verValue = (ushort)val;
            doors = Math.Max(1, Math.Min(3, (verValue / 10000)));
            edition = Math.Max(0, Math.Min(7, ((verValue % 10000) / 1000)));
            build = verValue % 1000;
        }

        private void UpdateVersionValue()
        {
            verValue = (ushort)((doors * 10000) + (edition * 1000) + build);
        }

        public override string ToString()
        {
            if (verValue != 0)
            {
                return verValue.ToString();
            }
            else
            {
                return "-----";
            }
        }
    }
}
